{extend name='comm/base' /}

{block name='header'}
{include file='comm/header'}
{/block}

{block name='slider'}
{include file='comm/slider'}
{/block}

{block name='main'}
<div class="main-content">
    <div class="main-content-inner">
        <div class="breadcrumbs ace-save-state" id="breadcrumbs">
            <ul class="breadcrumb">
                <li>
                    <i class="ace-icon fa fa-home home-icon"></i>
                    <a href="#">系统设置</a>
                </li>
                <li class="active">配送规则</li>
            </ul><!-- /.breadcrumb -->
        </div>
        <div class="page-content">

            <div class="page-header">
                <h1>
                    配送规则
                </h1>
            </div><!-- /.page-header -->
            <div class="row" id="form">
                <div class="col-xs-12">
                    <!-- PAGE CONTENT BEGINS -->
                    <form class="form-horizontal" role="form">
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-left must">计费方式(距离):</label>
                            <div class="col-sm-9 col-xs-12">
                                <div class="form-group">
                                    <div class="ban">
                                        <span class="input-group-addon">起步价</span>
                                        <input type="text" onkeyup="this.value=this.value.replace(/[^0-9\.]/g,'')" class="form-control valid" value="{$rule['weight_rule']['weight_start_fee']}" id="weight_start_fee"/>
                                        <span class="input-group-addon">元</span>
                                    </div>
                                    <div class="ban">
                                        <input type="text" onkeyup="this.value=this.value.replace(/[^0-9\.]/g,'')"  class="form-control valid" value="{$rule['distance_rule']['distance_for_free']}" id="distance_for_free"/>
                                        <span class="input-group-addon">公里内免费</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-left"></label>
                            <div class="col-sm-9 col-xs-12">
                                <div class="form-group">
                                    <div class="ban">
                                        <span class="input-group-addon">超出起步范围</span>
                                        <input type="text" onkeyup="this.value=this.value.replace(/[^0-9\.]/g,'')"  class="form-control valid" value="{$rule['distance_rule']['distance_over_start_range']}" id="distance_over_start_range"/>
                                    </div>
                                    <div class="ban">
                                        <span class="input-group-addon">公里内 每公里加价</span>
                                        <input type="text" onkeyup="this.value=this.value.replace(/[^0-9\.]/g,'')"  class="form-control valid" value="{$rule['distance_rule']['distance_over_start_perfee']}" id="distance_over_start_perfee"/>
                                        <span class="input-group-addon">元</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-left"></label>
                            <div class="col-sm-9 col-xs-12">
                                <div class="form-group">
                                    <div class="ban">
                                        <span class="input-group-addon">超出</span>
                                        <input type="text" onkeyup="this.value=this.value.replace(/[^0-9\.]/g,'')"  class="form-control valid" value="{$rule['weight_rule']['weight_over_second']}" id="distance_over_second"/>
                                    </div>
                                    <div class="ban">
                                        <span class="input-group-addon">公里 小于</span>
                                        <input type="text" onkeyup="this.value=this.value.replace(/[^0-9\.]/g,'')"  class="form-control valid" value="{$rule['weight_rule']['weight_max_limit']}" id="diatance_max_limit"/>
                                        <span class="input-group-addon">公里 每公里加价</span>
                                        <input type="text" onkeyup="this.value=this.value.replace(/[^0-9\.]/g,'')"  class="form-control valid" value="{$rule['weight_rule']['weight_fixed_fee']}" id="distance_fixed_fee"/>
                                        <span class="input-group-addon">元</span>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-left must">计费方式(重量):</label>
                            <div class="col-sm-9 col-xs-12">
                                <div class="form-group">
                                    <div class="ban">
                                        <input type="text" onkeyup="this.value=this.value.replace(/[^0-9\.]/g,'')"  class="form-control valid" value="{$rule['weight_rule']['weight_for_free']}" id="weight_for_free"/>
                                        <span class="input-group-addon">公斤内免费</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-left"></label>
                            <div class="col-sm-9 col-xs-12">
                                <div class="form-group">
                                    <div class="ban">
                                        <span class="input-group-addon">超出起步范围</span>
                                        <input type="text" onkeyup="this.value=this.value.replace(/[^0-9\.]/g,'')"  class="form-control valid" value="{$rule['weight_rule']['weight_over_start_range']}" id="weight_over_start_range"/>
                                    </div>
                                    <div class="ban">
                                        <span class="input-group-addon">公斤内 每增加1公斤</span>
                                        <input type="text" onkeyup="this.value=this.value.replace(/[^0-9\.]/g,'')"  class="form-control valid" value="{$rule['weight_rule']['weight_over_start_perfee']}" id="weight_over_start_perfee"/>
                                        <span class="input-group-addon">元</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-left"></label>
                            <div class="col-sm-9 col-xs-12">
                                <div class="form-group">
                                    <div class="ban">
                                        <span class="input-group-addon">超出</span>
                                        <input type="text" onkeyup="this.value=this.value.replace(/[^0-9\.]/g,'')"  class="form-control valid" value="{$rule['weight_rule']['weight_over_second']}" id="weight_over_second"/>
                                    </div>
                                    <div class="ban">
                                        <span class="input-group-addon">公斤 小于</span>
                                        <input type="text" onkeyup="this.value=this.value.replace(/[^0-9\.]/g,'')"  class="form-control valid" value="{$rule['weight_rule']['weight_max_limit']}" id="weight_max_limit"/>
                                        <span class="input-group-addon">公斤内 每公斤加价</span>
                                        <input type="text" onkeyup="this.value=this.value.replace(/[^0-9\.]/g,'')"  class="form-control valid" value="{$rule['weight_rule']['weight_fixed_fee']}" id="weight_fixed_fee"/>
                                        <span class="input-group-addon">元</span>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="space-4"></div>
                        <div class="space-4"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-left">特殊时段费用:</label>
                            <div class="col-sm-9 col-xs-12">
                                <div class="form-group">
                                    <div class="ban">
                                            <input type="datetime" id="start_time_one" value="{$rule['special_time_rule']['start_time_one']}" class="form-control valid" readonly>

                                            <span class="input-group-addon">
                                              <i class="fa fa-clock-o bigger-110"></i>
                                             </span>
                                    </div>
                                    <div class="ban">
                                        <input type="datetime"  id="end_time_one" value="{$rule['special_time_rule']['end_time_one']}"
                                               class="form-control valid" readonly>
                                        <span class="input-group-addon">
                                              <i class="fa fa-clock-o bigger-110"></i>
                                             </span>
                                        <span class="input-group-addon">加收</span>
                                        <input id="add_fee_one" onkeyup="this.value=this.value.replace(/[^0-9\.]/g,'')"  value="{$rule['special_time_rule']['add_fee_one']}"  type="text" class="form-inline">
                                        <span class="input-group-addon">元</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-left"></label>
                            <div class="col-sm-9 col-xs-12">
                                <div class="form-group">
                                    <div class="ban">
                                        <input type="datetime" id="start_time_two" value="{$rule['special_time_rule']['start_time_two']}"  class="form-control valid" readonly>
                                        <span class="input-group-addon">
                                          <i class="fa fa-clock-o bigger-110"></i>
                                         </span>
                                    </div>
                                    <div class="ban">
                                        <input type="datetime" value="{$rule['special_time_rule']['end_time_two']}"  id="end_time_two" class="form-control valid" readonly>
                                        <span class="input-group-addon">
                                          <i class="fa fa-clock-o bigger-110"></i>
                                         </span>
                                        <span class="input-group-addon">加收</span>
                                        <input id="add_fee_two" onkeyup="this.value=this.value.replace(/[^0-9\.]/g,'')"  value="{$rule['special_time_rule']['add_fee_two']}"  type="text" class="form-inline">
                                        <span class="input-group-addon">元</span>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-left must">封顶金额:</label>
                            <div class="col-sm-9 col-xs-12">
                                <div class="form-group">
                                    <div class="ban">
                                        <input type="text" onkeyup="this.value=this.value.replace(/[^0-9\.]/g,'')"  class="form-control valid" id="max_fee" value="{$rule['max_fee']}"/>
                                        <span class="input-group-addon">元</span>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="clearfix form-actions">
                            <div class="col-md-offset-3 col-md-9">
                                <button class="btn btn-primary" type="button" id="save_btn">
                                    保存
                                </button>
                            </div>
                        </div>

                        <div class="hr hr-24"></div>
                    </form>

                    <!-- PAGE CONTENT ENDS -->
                </div><!-- /.col -->
            </div><!-- /.row -->
        </div><!-- /.page-content -->
    </div>
</div><!-- /.main-content -->
{/block}

{block name='footer'}
{include file='comm/footer'}
{/block}
{block name='script'}
<script src="__ace_js__/jquery-2.1.4.min.js"></script>
<script type="text/javascript">
    if ('ontouchstart' in document.documentElement) document.write("<script src='__ace_js__/jquery.mobile.custom.min.js'>" + "<" + "/script>");
</script>
<!-- ace scripts -->
<script src="__ace_js__/ace-elements.min.js"></script>
<script src="__ace_js__/bootstrap-timepicker.min.js"></script>
<script src="__ace_js__/moment.min.js"></script>
<script src="__ace_js__/bootstrap-datetimepicker.min.js"></script>
<link rel="stylesheet" href="__ace_css__/bootstrap-timepicker.min.css"/>
<link rel="stylesheet" href="__ace_css__/bootstrap-datetimepicker.min.css"/>

<script lang="javascript">

    $('#start_time_one,#end_time_one,#start_time_two,#end_time_two').timepicker({
        minuteStep: 60,
        showSeconds: false,
        showMeridian: false,
        disableFocus: true,
        icons: {
            up: 'fa fa-chevron-up',
            down: 'fa fa-chevron-down'
        }
    }).on('focus', function () {
        $('#start_time_picker').timepicker('showWidget');
    }).next().on(ace.click_event, function () {
        $(this).prev().focus();
    });

    $('#save_btn').click(function () {

        var distance_start_fee = $('#distance_start_fee').val();
        var distance_for_free = $('#distance_for_free').val();
        var distance_over_start_range = $('#distance_over_start_range').val();
        var distance_over_start_perfee = $('#distance_over_start_perfee').val();
        var distance_over_second = $('#distance_over_second').val();
        var distance_fixed_fee = $('#distance_fixed_fee').val();

        var weight_start_fee = $('#weight_start_fee').val();
        var weight_for_free = $('#weight_for_free').val();
        var weight_over_start_range = $('#weight_over_start_range').val();
        var weight_over_start_perfee = $('#weight_over_start_perfee').val();
        var weight_over_second = $('#weight_over_second').val();
        var weight_max_limit = $('#weight_max_limit').val();
        var weight_fixed_fee = $('#weight_fixed_fee').val();

        var start_time_one = $('#start_time_one').val();
        var end_time_one = $('#end_time_one').val();
        var add_fee_one = $('#add_fee_one').val();
        var start_time_two = $('#start_time_two').val();
        var end_time_two = $('#end_time_two').val();
        var add_fee_two = $('#add_fee_two').val();
        var max_fee = $('#max_fee').val();

        var data = {
            "weight_start_fee": weight_start_fee,
            "weight_for_free": weight_for_free,
            "weight_over_start_range": weight_over_start_range,
            "weight_over_start_perfee": weight_over_start_perfee,
            "weight_over_second": weight_over_second,
            "weight_max_limit": weight_max_limit,
            "weight_fixed_fee": weight_fixed_fee,
            "distance_start_fee": distance_start_fee,
            "distance_for_free": distance_for_free,
            "distance_over_start_range": distance_over_start_range,
            "distance_over_start_perfee": distance_over_start_perfee,
            "distance_over_second": distance_over_second,
            "distance_fixed_fee": distance_fixed_fee,
            "start_time_one": start_time_one,
            "end_time_one": end_time_one,
            "add_fee_one": add_fee_one,
            "start_time_two": start_time_two,
            "end_time_two": end_time_two,
            "add_fee_two": add_fee_two,
            "max_fee": max_fee
        };
        var res = validate();
        if(res == false){
            swal({
                type: 'warning', // 弹框类型
                title: '请将数据填写完整', //标题
                confirmButtonColor: '#438EB9',// 确定按钮的 颜色
                confirmButtonText: '确定',// 确定按钮的 文字
            });
            return false;
        }
        $.ajax({
            url: "{:url('admin.delivery_rule.create')}",
            type: 'POST',
            dataType: 'JSON',
            data: data,
            success: function (res) {
                if (res.code == 1) {
                    swal({
                        type: 'success', // 弹框类型
                        title: '操作成功', //标题
                        confirmButtonColor: '#438EB9',// 确定按钮的 颜色
                        confirmButtonText: '确定',// 确定按钮的 文字
                    }).then((isConfirm) => {
                        //判断 是否 点击的 确定按钮
                        if (isConfirm.value) {
                            location.reload();
                        }
                    });
                } else {
                    swal({
                        type: 'warning', // 弹框类型
                        title: res.msg, //标题
                        confirmButtonColor: '#438EB9',// 确定按钮的 颜色
                        confirmButtonText: '确定',// 确定按钮的 文字
                    });
                }
                return false;
            }, error: function (e) {
                swal({
                    type: 'error', // 弹框类型
                    title: e.msg, //标题
                    confirmButtonColor: '#438EB9',// 确定按钮的 颜色
                    confirmButtonText: '确定',// 确定按钮的 文字
                });
            }
        })
    })

    function validate(){
        var ipt = document.getElementById("form").getElementsByTagName("input"); //查找divbox这个div里的所有文本框
        for(var i = 0; i < ipt.length; i++){ //循环
            if(ipt[i].value.length == 0){ //如果其中一个文本框没有填写
                ipt[i].focus(); //定位到没有填写的文本框
                return false; //返回false
            }
        }
        return true; //都已经填写，返回true
    }


</script>
{/block}






